<template>
  <div>
    <WangEditor :has-author="false" :is-show-card="false" @submit="submit" :is-submit="true" :base-info="baseInfo"></WangEditor>
  </div>
</template>

<script setup lang="ts">
import WangEditor from "@/components/WangEditor/index.vue";
import { onBeforeMount, ref } from "vue";
import { getArtInfo, editArt, createArt } from "@/api/modules/about";
import { useRoute, useRouter } from "vue-router";

const route = useRoute();
const router = useRouter();

const baseInfo = ref({ title: "", author: "", cont: "" });

const getInfo = async () => {
  if (route.query.article_id) {
    const { data } = await getArtInfo({ id: parseInt(route.query.article_id as string) });
    baseInfo.value = data as any;
  }
};

const submit = async (val: any) => {
  if (route.query.article_id) {
    await editArt({ categoryId: parseInt(route.query.id as string), ...val, id: parseInt(route.query.article_id as string) });
  } else {
    await createArt({ ...val, categoryId: parseInt(route.query.id as string) });
  }
  router.back();
};

onBeforeMount(() => {
  Promise.all([getInfo()]);
});
</script>

<style></style>
